package com.sensePlusVR.utils;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;

/**
 * 
 * @author: Loren
 * @create: 2016-7-4下午8:07:06
 * @desc: 统一存放网络请求Url
 * 
 *        密码的加密方式改为AES加密，key是QWEREWQWERTREWER
 * 
 * 
 * servers.senselovers.com
 * 
 */

public class ConstantURL {
	
	/**
	 * 检查URL文件
	 */
	 public static void checkURL(Context context){
		 
		 
		 	
		    String configPath = FileUtils.getSDcardDir()+Constant.PATH_NATIVE_URL;
		    
		    
		    if(!FileUtils.isFileExist(configPath))
		    	return;
		    
		      
			InputStream fin = null;
			try {
				fin = new FileInputStream(configPath);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			InputStreamReader inputReader = new InputStreamReader(fin);
			
			BufferedReader bufferReader = new BufferedReader(inputReader);
			
			String strLine = null;
			
			try {
				while((strLine=bufferReader.readLine())!=null){
					
					if(strLine.startsWith(BASE_URL_NATIVE_DEV) || strLine.startsWith(BASE_URL_NATIVE_TEST)){
						
						BURIED_MODE = Constant.BURIED_MODE_DEBUG;
						
						VALUE_CLIENT_ID = Constant.VALUE_CLIENT_ID_DEBUG;
						
						VALUE_CHANNEL_ID = Constant.VALUE_CHANNEL_ID_DEBUG;
						
						
						if(strLine.startsWith(BASE_URL_NATIVE_DEV)){
							
							BASE_URL_NATIVE = BASE_URL_NATIVE_DEV;
							
						}else if(strLine.startsWith(BASE_URL_NATIVE_TEST)){
							
							BASE_URL_NATIVE = BASE_URL_NATIVE_TEST;
							
						}
						
						BASE_URL_ACCOUTN_NATIVE = BASE_URL_NATIVE + "/account/";
						BASE_URL_SEARCH_NATIVE = BASE_URL_NATIVE + "/resource/";
						BASE_URL_UPLOAD_NATIVE = BASE_URL_NATIVE + "/statistics/";
						BASE_URL_BURIED_NATIVE = BASE_URL_NATIVE + "/logs-downtank/";
						
						
						BASE_URL_ACCOUTN = BASE_URL_ACCOUTN_NATIVE;
						
						BASE_URL_SEARCH = BASE_URL_SEARCH_NATIVE;
						
						BASE_URL_UPLOAD = BASE_URL_UPLOAD_NATIVE;
						
						BASE_URL_BURIED = BASE_URL_BURIED_NATIVE;
						
						 LOGIN_URL = BASE_URL_ACCOUTN + "v2/authenticate";

						 ACCOUNT_URL = BASE_URL_ACCOUTN + "v2/account";
						
						 LOGIN_OUT_URL = BASE_URL_ACCOUTN + "v2/logout";

						 REGISTER_URL = BASE_URL_ACCOUTN + "v2/register";

						 RESET_PWD_URL = BASE_URL_ACCOUTN + "v2/account/reset_password";

						 GET_VER_CODE_URL = BASE_URL_ACCOUTN + "v2/account/verificationCode.json";

						 TOKEN_LEASE_URL = BASE_URL_ACCOUTN + "v2/token_lease";

						 CHANGE_PWD_URL = BASE_URL_ACCOUTN + "v2/account/change_password";
	
						 CHANGE_PHONE_NUM_URL = BASE_URL_ACCOUTN + "v2/register";

						 VIDEO_LIST = BASE_URL_SEARCH + "v2/video/search";
	
						 GAME_LIST = BASE_URL_SEARCH + ResVersion+"/game/search?device=android&gameactor=yes";
	
						 ACTOR_LIST = BASE_URL_SEARCH + "v2/actor/search?";
	
						 ACTOR_LIST_BY_NAME = BASE_URL_SEARCH + "v2/actor/searchbyname?name=";
						
						 ACTOR_LIST_BY_IDS = BASE_URL_SEARCH + "v2/actor/searchbyids";

						 APP_UPLOAD_STATISTICS = BASE_URL_UPLOAD + "v2/appinfo/activetime";

						 VIDEO_ACTIVE_TIME = BASE_URL_UPLOAD + "v2/videoinfo/activetime";

						 VIDEO_COMMENT = BASE_URL_UPLOAD + "v2/videoinfo/comment";

						 VIDEO_RATING = BASE_URL_UPLOAD + "v2/videoinfo/rating";

						 GAME_ACTIVE_TIME = BASE_URL_UPLOAD + "v2/gameinfo/activetime";

						 GAME_COMMENT = BASE_URL_UPLOAD + "v2/gameinfo/comment";

						 GAME_RATING = BASE_URL_SEARCH + ResVersion + "/praise/addPraise";;

						 FOLLOW_SAVE_SINGLE = BASE_URL_SEARCH + ResVersion + "/follow?";
						

						 FOLLOW_SAVE_MULTI = BASE_URL_SEARCH + "v2/followmany?";

						 COLLECTION_SAVE_SINGLE = BASE_URL_SEARCH + ResVersion+"/collection?";

						 COLLECTION_SAVE_MULTI = BASE_URL_SEARCH + ResVersion+"/collectionmany?";
						

						 PUT_BROWSER_TIMES = BASE_URL_UPLOAD + "v2/gameinfo/putbrowser?";
						
						 GET_BROWSER_TIMES = BASE_URL_UPLOAD + "v2/gameinfo/getbrowser";

						 GET_COLLECTION_FOLLOW_IDS = BASE_URL_SEARCH + ResVersion + "/alldnyinfo?";

						 GET_LIST_BY_IDS = BASE_URL_SEARCH + ResVersion+"/game/searchbyid?device=android&gameactor=yes";
	
						 GET_GAME_BACKGROUND_MUSIC = BASE_URL + ":8080/data/music/findPageList";

						 GET_GAME_RATINGS = BASE_URL_UPLOAD + "v2/gameinfo/rating?";

						 FOLLOW_CANCEL_SINGLE = BASE_URL_SEARCH + ResVersion + "/follow?";
	
						 COLLECTION_CANCEL_SINGLE = BASE_URL_SEARCH + ResVersion+"/collection?";

						 FORGET_PASSWORD = BASE_URL_ACCOUTN + "v2/forgot/password";

						 VERSION_UPDATE = BASE_URL_SEARCH + "v2/appversioninfo/findappversion";
	
						 VERIFY_EMAIL_AGAIN = BASE_URL_ACCOUTN + "v2/againget/verification/email";

						 FEEDBACK = BASE_URL_UPLOAD + "v2/appinfo/save";
						 
						 CPUINFO_CONTROLLER = BASE_URL_SEARCH + "v2/query/cpuinfo?info=";
						 
						 DOWNLOAD_RECORD = BASE_URL_SEARCH + "v4/game/addDownloadRecord";
						 
						 FEEDBACK_LIST = BASE_URL_UPLOAD + "v2/appinfo/feedback/list";
						 
						 FEEDBACK_NOT_READ_COUNT = BASE_URL_UPLOAD + "v2/appinfo/feedback/notice";
						 
						 BANNER_LIST = BASE_URL_SEARCH + "v2/query/banners?type=";
						 
						 BURIED_ACTIVE_UPLOAD = BASE_URL_BURIED + "v1/active";
						 
						 BURIED_EVENT_UPLOAD = BASE_URL_BURIED + "v1/event";

					}else if(strLine.startsWith(Constant.NATIVE_BUNDLE_SWITCH)){
						
						Constant.nativeBundleSwitch = true;
						String temp[] = strLine.split("=");
						if (temp.length == 2){
							if (!temp[1].equalsIgnoreCase("true")){
								Constant.nativeBundleName = temp[1];
							}
						}
					}
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			try {
				bufferReader.close();
				
				inputReader.close();
				
				fin.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 
			
	 }
	 
	 /**
	  * App为测试版本还是发布版本
	  * Debug
	  * Prod
	  */
	 public static String BURIED_MODE = Constant.BURIED_MODE_PROD;
	 
	 public static String VALUE_CLIENT_ID = Constant.VALUE_CLIENT_ID_PROD;
	 
	 public static String VALUE_CHANNEL_ID = Constant.VALUE_CHANNEL_ID_PROD;
	 
	  /**
	   * 资源版本	
	   */
	  public static final String ResVersion = "v4";
	
	  /**
	   * 外网用户
	   */
	  public static String BASE_URL = "https://servers.senselovers.com/";
	  /**
	   用户BASE URL
	   */
	  public static String BASE_URL_ACCOUTN = BASE_URL + "account/";
	  /**
	   * 搜索 BASE URL
	   */
	  public static String BASE_URL_SEARCH = BASE_URL + "resource/";
	  
	  /**
	   * 打点 BASE URL
	   */
	  public static String BASE_URL_UPLOAD = BASE_URL + "statistics/";
	  
	  /**
	   * 埋点BASE URL
	   */
	  public static String BASE_URL_BURIED = BASE_URL + "logs-downtank/";
	  
	/**
	 * 内网测试
	 */
	public static String BASE_URL_NATIVE_DEV = "http://192.168.10.241";//开发人员常用
	public static String BASE_URL_NATIVE_TEST = "http://192.168.10.242";//测试人员常用
	
	public static String BASE_URL_NATIVE = "http://192.168.10.241";//默认设置为241
	public static String BASE_URL_ACCOUTN_NATIVE = BASE_URL_NATIVE + "/account/";
	public static String BASE_URL_SEARCH_NATIVE = BASE_URL_NATIVE + "/resource/";
	public static String BASE_URL_UPLOAD_NATIVE = BASE_URL_NATIVE + "/statistics/";
	public static String BASE_URL_BURIED_NATIVE = BASE_URL_NATIVE + "/logs-downtank/";
	
	/**
	 * 内网开发(本地不用放置nativeUrl.txt)
	 */
//	public static String BASE_URL = "http://192.168.10.241";
//	public static String BASE_URL_ACCOUTN = BASE_URL + "/account/";
//	public static String BASE_URL_SEARCH = BASE_URL + "/resource/";
//	public static String BASE_URL_UPLOAD = BASE_URL + "/statistics/";
//    public static String BASE_URL_BURIED = BASE_URL + "/logs-downtank/";	
	
	
	/**
	 * 用户登录
	 */
	public static String LOGIN_URL = BASE_URL_ACCOUTN + "v2/authenticate";

	/**
	 * 获取帐号信息
	 */
	public static String ACCOUNT_URL = BASE_URL_ACCOUTN + "v2/account";
	
	/**
	 * 退出登录
	 */
	public static String LOGIN_OUT_URL = BASE_URL_ACCOUTN + "v2/logout";

	/**
	 * 账号注册
	 */
	public static String REGISTER_URL = BASE_URL_ACCOUTN + "v2/register";

	/**
	 * 用户修改密码
	 */
	public static String RESET_PWD_URL = BASE_URL_ACCOUTN + "v2/account/reset_password";

	/**
	 * 获取验证码
	 */
	public static String GET_VER_CODE_URL = BASE_URL_ACCOUTN + "v2/account/verificationCode.json";

	/**
	 * 延长 Access Token (Cookie) 生命期
	 */
	public static String TOKEN_LEASE_URL = BASE_URL_ACCOUTN + "v2/token_lease";
	/**
	 * 修改密码
	 */
	public static String CHANGE_PWD_URL = BASE_URL_ACCOUTN + "v2/account/change_password";
			

	/**
	 * 更换手机号
	 */
	public static String CHANGE_PHONE_NUM_URL = BASE_URL_ACCOUTN + "v2/register";
	
	/**
	 * 获取视频列表
	 */
	public static String VIDEO_LIST = BASE_URL_SEARCH + "v2/video/search";
	
	/**
	 * 获取游戏列表
	 */
	public static String GAME_LIST = BASE_URL_SEARCH + ResVersion+"/game/search?device=android&gameactor=yes";
	//public static String GAME_LIST = BASE_URL_SEARCH + "v2/game/search?device=android&gameactor=yes&type=likereal";
	/**
	 * 获取所有演员信息列表
	 * http://ip:8080/vr/v2/actor/search?currentpage=%d&&pagesize=%d
	 */
	public static String ACTOR_LIST = BASE_URL_SEARCH + "v2/actor/search?";
	/**
	 * 获取演员所对应的游戏列表
	 * http://ip:8080/vr/v2/actor/searchbyname?name=%s
	 */
	public static String ACTOR_LIST_BY_NAME = BASE_URL_SEARCH + "v2/actor/searchbyname?name=";
	
	/**
	 * http://ip:8090/vr/v2/actor/searchbyids
	 * 参数还是List<int>
	 * 通过id获取actor，还没有通过多个id
	 */
	public static String ACTOR_LIST_BY_IDS = BASE_URL_SEARCH + "v2/actor/searchbyids";
	
	/**
	 * 上传App统计信息
	 */
	public static String APP_UPLOAD_STATISTICS = BASE_URL_UPLOAD + "v2/appinfo/activetime";
	/**
	 * 上传视频观看信息
	 */
	public static String VIDEO_ACTIVE_TIME = BASE_URL_UPLOAD + "v2/videoinfo/activetime";
	
	/**
	 * 上传视频评论
	 */
	public static String VIDEO_COMMENT = BASE_URL_UPLOAD + "v2/videoinfo/comment";
	
	/**
	 * 上传视频赞
	 */
	public static String VIDEO_RATING = BASE_URL_UPLOAD + "v2/videoinfo/rating";
	
	/**
	 * 上传游戏玩的信息
	 */
	public static String GAME_ACTIVE_TIME = BASE_URL_UPLOAD + "v2/gameinfo/activetime";
	
	/**
	 * 上传游戏评论
	 */
	public static String GAME_COMMENT = BASE_URL_UPLOAD + "v2/gameinfo/comment";
	
	/**
	 * 上传游戏赞
	 * GET
	 */
	public static String GAME_RATING = BASE_URL_SEARCH + ResVersion + "/praise/addPraise";
	
	/**
	 * 保存用户关注信息，保存单个
	 * http://ip:8080/vr/v2/follow?userid=%d&&actorid=%d
	 * POST
	 */
	public static String FOLLOW_SAVE_SINGLE = BASE_URL_SEARCH + ResVersion + "/follow?";
	
	/**
	 * 保存用户关注信息，保存多个
	 * http://ip:8080/vr/v2/followmany?userid=%d&&actorstr=%s
	 */
	public static String FOLLOW_SAVE_MULTI = BASE_URL_SEARCH + "v2/followmany?";
	
	/**
	 * 保存用户收藏信息，保存单个
	 * http://ip:8080/vr/v2/collection?userid=%d&&gameid=%d 
	 * POST
	 */
	public static String COLLECTION_SAVE_SINGLE = BASE_URL_SEARCH + ResVersion+"/collection?";
	
	/**
	 * 保存用户收藏信息，保存多个
	 * http://ip:8080/vr/v2/collectionmany?userid=%d&&gamestr=%s
	 */
	public static String COLLECTION_SAVE_MULTI = BASE_URL_SEARCH + ResVersion+"/collectionmany?";
	
	/**
	 * 获取用户关注信息
	 * http://ip:8080/vr/v2/follow?userid=%d
	 */
	//public static String GET_FOLLOW = BASE_URL_ACCOUTN + "v2/follow?";
	
	/**
	 * 获取用户收藏信息
	 * http://ip:8080/vr/v2/collection?userid=%d
	 */
	//public static String GET_COLLECTION = BASE_URL_ACCOUTN + "v2/collection?";
	
	/**
	 * http://ip:8070/vr/v2/gameinfo/putbrowser?resid=%d
	 * POST
	 *	增加一次resid对应的game浏览次数，如果返回E109错误，请重试
	 */
	public static String PUT_BROWSER_TIMES = BASE_URL_UPLOAD + "v2/gameinfo/putbrowser?";
	
	/**
	 * http://ip:8070/vr/v2/gameinfo/putbrowser?resid=%d
	 * POST
	 * 获取通过传递的gameIds获取到相应game的的浏览量
	 *参数还是List<int>
	 */
	public static String GET_BROWSER_TIMES = BASE_URL_UPLOAD + "v2/gameinfo/getbrowser";
	
	
	/**
	 * 返回所有collection 和 follow 信息id集合
	 * http://ip:8080/vr/v2/alldnyinfo?userid=%d
	 * 返回所有收藏和关注的信息 "collection=;follow="
	 */
	
	public static String GET_COLLECTION_FOLLOW_IDS = BASE_URL_SEARCH + ResVersion + "/alldnyinfo?";
	
	/**
	 * 根据ids获取collection 或者 follow 列表详细信息
	 * http://ip:8090/vr/v2/game/searchbyid?device=ios/android?&gameactor=yes
	 */
	public static String GET_LIST_BY_IDS = BASE_URL_SEARCH + ResVersion+"/game/searchbyid?device=android&gameactor=yes";
	
	/**
	 * 获取游戏背景音乐
	 * GET
	 * page:第几页，默认为第1页
	 * rows:每页显示多少行，默认为30行
	 */
	public static String GET_GAME_BACKGROUND_MUSIC = BASE_URL + ":8080/data/music/findPageList";
	/**
	 * 获取游戏被多少人赞过
	 * GET
	 * userid=%d&&gameid=%d
	 * http://192.168.10.241:8070/vr/v2/gameinfo/rating?gameid=8
	 */
	public static String GET_GAME_RATINGS = BASE_URL_UPLOAD + "v2/gameinfo/rating?";
	
	/**
	 * 取消关注
	 * PUT
	 * userid=%d&&gameid=%d
	 */
	public static String FOLLOW_CANCEL_SINGLE = BASE_URL_SEARCH + ResVersion + "/follow?";
	
	/**
	 * 取消收藏
	 * PUT
	 * userid=%dgameid=%d
	 */
	public static String COLLECTION_CANCEL_SINGLE = BASE_URL_SEARCH + ResVersion+"/collection?";
	
	/**
	 * 忘记密码
	 * POST
	 * loginName
	 * email
	 * http://www.jwaoo.com:8080/account/v2/forgot/password
	 */
	public static String FORGET_PASSWORD = BASE_URL_ACCOUTN + "v2/forgot/password";
	
	
	
	/**
	 * 版本更新
	 */
	public static String VERSION_UPDATE = BASE_URL_SEARCH + "v2/appversioninfo/findappversion";
	
	/**
	 * 再次发送验证码
	 */
	public static String VERIFY_EMAIL_AGAIN = BASE_URL_ACCOUTN + "v2/againget/verification/email";
	
	/**
	 * feedback 接口
	 * POST
	 * feedback,email
	 */
	public static String FEEDBACK = BASE_URL_UPLOAD + "v2/appinfo/save";
	
	/**
	 * cpuinfo 接口
	 * GET 请求
	 */
	public static String CPUINFO_CONTROLLER = BASE_URL_SEARCH + "v2/query/cpuinfo?info=";
	
	/**
	 * 上传下载次数
	 * POST请求
	 */
	public static String DOWNLOAD_RECORD = BASE_URL_SEARCH + "v4/game/addDownloadRecord";
	
	/**
	 * Feedback消息
	 * POST请求
	 */
	public static String FEEDBACK_LIST = BASE_URL_UPLOAD + "v2/appinfo/feedback/list";
	
	/**
	 * Feedback未读消息数量
	 * POST请求
	 */
	public static String FEEDBACK_NOT_READ_COUNT = BASE_URL_UPLOAD + "v2/appinfo/feedback/notice";
	
	/**
	 * Banner新片预告接口
	 * GET请求
	 */
	public static String BANNER_LIST = BASE_URL_SEARCH + "v2/query/banners?type=";
	
	/**
	 * 埋点 活跃度Active接口
	 * POST请求
	 */
	public static String BURIED_ACTIVE_UPLOAD = BASE_URL_BURIED + "v1/active";
	
	
	public static String BURIED_EVENT_UPLOAD = BASE_URL_BURIED + "v1/event";
	
	
	
}




